Building a Tip of the Day Application (Part 3): Submitting Tips to the Web Service
Table of Contents
Building the Calendar Browse Interface
Integrating the DateChooser (calendar) component is a fairly simple
proposition after you've built the dateFormat function.
When a user clicks a calendar date, the DateChooser code throws a change
event, which you can easily trap.
When a user clicks a date, you want to send her to the tip screen and show her the tip for the day she chose.
- On the search screen, select the DateChooser instance and open the Behaviors panel.
- Click the Add Behavior button and select Screen > Go to Slide from the contextual menu.
- In the Select Screen dialog box, select the tip screen and click the OK button.
- In the Behaviors panel, change the event from
scrollto change. Now when a user clicks a date, the screen will change.
Next, you need to set the value of the tipdate_str in
the DataHolder to the value of the currently selected date. Here's
why: To get the getTipByDate function to work in the web
service, you need to pass it a date. The date parameter that’s sent
to the web service is bound to the dataHolder_dh.tipdate_str parameter.
Therefore, before sending the user back to the tip page, you have to
update this date string in the DataHolder component to the date that
the user clicked on the calendar. Also, when the user clicks a date,
the date is passed as an ActionScript date object that you need to
convert to MM/DD/YYYY format before you can send it to the web service.
-
Select the DataChooser instance on the search screen. Open the Actions panel and add the following line of code above the // GoTo Screen comment.
this._parent._parent._parent.dataHolder_dh.tipdate_str = this._parent._parent._parent.dateFormat(this.selectedDate);
This code sets the value of
tipdate_strin thedataHolder_dhinstance to the value of the currently selected date and formats the date using the custom formatting function. Note that since you defined the function on the presentation screen, you have to use dot syntax to reference the function just as you would for a component instance. -
Enter the following code above the code you added in step 1.
if (this.selectedDate == undefined) { return; }The code checks if the current
selectedDateis undefined. If no date is defined, the rest of the code (including setting the value of thetipdate_strproperty in the DataHolder and the Go to Slide behavior) is skipped.Why do you need to do this? When working with the DateChooser component, if a user clicks a date to select it, then clicks the same date again, it becomes deselected. This leaves the value of
selectedDateundefined. However, the Tip of the Day code would still trigger the change event.To work around this, you're using the code in Step 2 to check the value of
selectedDateto see if it is defined or not. If the value hasn’t been defined, then the user has most likely selected the same date twice and therefore you can disregard theclickevent.